//定义JS常量
var EMAIL_REGULAR_EXPRESSION=  "^[.\\-_a-zA-Z0-9]+@[\\-_a-zA-Z0-9]+\\.[.a-zA-Z0-9]";
var PASSWORD_REGULAR_EXPRESSION="^\\w{6,20}$";
var NICKNAME_REGULAR_EXPRESSION="^[a-z0-9\\u4e00-\\u9fa5]{2,20}$";
var VERIFY_CODE_EXPRESSION="^\\w{4}$";
var QUECTION_ANSWER="^[a-z0-9\\u4e00-\\u9fa5]{2,40}$";

var MSG_EMIAL_NULL = "此项为必填项，请输入您的Email地址。";
var MSG_EMAIL_FORMAT_ERROR="您设置的Email格式不正确。请填写有效的Email地址。";
var MSG_EMAIL_USED="您设置的Email地址已存在，请选择另一个Email地址。";
var MSG_NICKNAME_NULL = "此项为必填项，请输入您的昵称。";
var MSG_NICKNAME_FORMAT_ERROR="您输入的昵称有误，请重新输入。</br>您的昵称可以由小写英文字母,中文,数字组成，长度2－20位。";
var MSG_NICKNAME_USED="该昵称已被使用，请重新输入。";
var MSG_PASSWORD_NULL = "此项为必填项，请设置您的密码。";
var MSG_PASSWORD_FORMAT_ERROR="您设置的密码有误，请重新输入您的密码可以由大小写英文字母、数字组成，长度6－20位。";
var MSG_PASSWORD_NOT_IDENTICAL="两次密码输入的不一致，请重新输入。";
var MSG_QUESTION_NULL="此项为必填项，请设置您的提问";
var MSG_QUESTION_FORMAT_ERROR="您设置的提问长度必须在2-40字节范围内";
var MSG_ANSWER_NULL="此项为必填项，请设置您的问题";
var MSG_ANSWER_FORMAT_ERROR="您设置的问题长度必须在2-40字节范围内";
var MSG_VERIFYCODE_NULL = "此项为必填项，请输入验证码。";
var MSG_VERIFYCODE_ERROR="您输入的验证码不正确，请重新输入。";

//表达式检测方法
function regularExpressionValid(controlToValidID,validationExpression)
{
    var objRegExp = new RegExp(validationExpression,"g");//创建正则表达式
    var objControlToValid=document.getElementById(controlToValidID);//需进行校验的字段
   	var isValid=objRegExp.test(objControlToValid.value);//开始校验，返回值为校验结果
   	return isValid;
}
function regist()
{
	var emailVal = txtEmail_check();
	var nameVal = txtNickName_check();
	var lpassVal = txtLPassword_check();
	var lrpassVal = txtLRepeatPass_check();
	var ppassVal = txtPPassword_check();
	var prpassVal = txtPRepeatPass_check();
	var quesVal = txtQuestion_check();
	var ansewVal = txtAnswer_check();
	var vercodeVal = txtVer_check();

	if(emailVal&&nameVal&&lpassVal&&lrpassVal&&ppassVal&&prpassVal&&quesVal&&ansewVal&&vercodeVal)
	{
		var regist = document.getElementById("btnRegister");
		regist.click();	
	}

}

function showRegister()
{
    var ck = document.getElementById("ckCheck");
    var btn = document.getElementById("validatemsg");
    if(ck.checked )
    {
        btn.style.display = "block";
    }
	else
        btn.style.display = "none";
}

function resultEmail(data)
{
	if(data==true){
		var txtEmailSpan = document.getElementById("tipEmail");
		txtEmailSpan.innerHTML = MSG_EMAIL_USED;
		txtEmailSpan.style.color = "red";
		document.getElementById("validatemsg").disabled=true;
	}
	else
	{
		document.getElementById("validatemsg").disabled=false;
	}
}
//Email验证
function txtEmail_check(data)
{
	var txtEmail = document.getElementById("txtEmail").value;
	var txtEmailSpan = document.getElementById("tipEmail");
	var isValid = regularExpressionValid("txtEmail",EMAIL_REGULAR_EXPRESSION);
	EmailValdate.isHasEmail(txtEmail,resultEmail);
	if(txtEmail=="")
	{
		txtEmailSpan.innerHTML = MSG_EMIAL_NULL;
		txtEmailSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtEmailSpan.innerHTML = MSG_EMAIL_FORMAT_ERROR;
		txtEmailSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtEmailSpan.innerHTML = "可以使用";
		txtEmailSpan.style.color = "#4F4F4F";
		return true;		
	}
}
function resultName(data)
{
	if(data==true)
	{
		var txtNameSpan = document.getElementById("tipName");
		txtNameSpan.innerHTML = MSG_NICKNAME_USED;
		txtNameSpan.style.color = "red";		
		document.getElementById("validatemsg").disabled=true;
	}
	else
	{
		document.getElementById("validatemsg").disabled=false;
	}
}
//昵称验证
function txtNickName_check()
{
	var txtName = document.getElementById("txtNickNam").value;
	var txtNameSpan = document.getElementById("tipName");
	var isValid = regularExpressionValid("txtNickNam",NICKNAME_REGULAR_EXPRESSION);
	NameValdate.isHasName(txtName,resultName);
	if(txtName=="")
	{
		txtNameSpan.innerHTML = MSG_NICKNAME_NULL;
		txtNameSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtNameSpan.innerHTML = MSG_NICKNAME_FORMAT_ERROR;
		txtNameSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtNameSpan.innerHTML = "可以使用";
		txtNameSpan.style.color = "#4F4F4F";
		return true;		
	}	
}
//登录密码验证
function txtLPassword_check()
{
	var txtLPassword = document.getElementById("txtLPassword").value;
	var txtLPasswordSpan = document.getElementById("tipLPwd");
	var isValid = regularExpressionValid("txtLPassword",PASSWORD_REGULAR_EXPRESSION);
	if(txtLPassword=="")
	{
		txtLPasswordSpan.innerHTML = MSG_PASSWORD_NULL;
		txtLPasswordSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtLPasswordSpan.innerHTML = MSG_PASSWORD_FORMAT_ERROR;
		txtLPasswordSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtLPasswordSpan.innerHTML = "可以使用";
		txtLPasswordSpan.style.color = "#4F4F4F";
		return true;		
	}	
}
//登入密码重复验证
function txtLRepeatPass_check()
{
	var txtLRepatePass = document.getElementById("txtLRepeatePass").value;
	var txtLRepatePassSpan = document.getElementById("tipLPwd2");
	var isValid = regularExpressionValid("txtLRepeatePass",PASSWORD_REGULAR_EXPRESSION);
	var txtLPassword = document.getElementById("txtLPassword").value;
	if(txtLRepatePass=="")
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_NULL;
		txtLRepatePassSpan.style.color = "red";
		return false;
	}
	else if(txtLRepatePass!=txtLPassword)
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_NOT_IDENTICAL;
		txtLRepatePassSpan.style.color = "red";
		return false;			
	}
	else if(!isValid)
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_FORMAT_ERROR;
		txtLRepatePassSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtLRepatePassSpan.innerHTML = "可以使用";
		txtLRepatePassSpan.style.color = "#4F4F4F";
		return true;		
	}	
}
//支付密码验证
function txtPPassword_check()
{
	var txtPPassword = document.getElementById("txtPPassword").value;
	var txtPPasswordSpan = document.getElementById("tipPPwd");
	var isValid = regularExpressionValid("txtPPassword",PASSWORD_REGULAR_EXPRESSION);
	if(txtPPassword=="")
	{
		txtPPasswordSpan.innerHTML = MSG_PASSWORD_NULL;
		txtPPasswordSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtPPasswordSpan.innerHTML = MSG_PASSWORD_FORMAT_ERROR;
		txtPPasswordSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtPPasswordSpan.innerHTML = "可以使用";
		txtPPasswordSpan.style.color = "#4F4F4F";
		return true;		
	}		
}
//支付密码重复验证
function txtPRepeatPass_check()
{
	var txtLRepatePass = document.getElementById("txtPRepeatePass").value;
	var txtLRepatePassSpan = document.getElementById("tipPPwd2");
	var isValid = regularExpressionValid("txtPRepeatePass",PASSWORD_REGULAR_EXPRESSION);
	var txtLPassword = document.getElementById("txtPPassword").value;
	if(txtLRepatePass=="")
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_NULL;
		txtLRepatePassSpan.style.color = "red";
		return false;
	}
	else if(txtLRepatePass!=txtLPassword)
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_NOT_IDENTICAL;
		txtLRepatePassSpan.style.color = "red";
		return false;			
	}
	else if(!isValid)
	{
		txtLRepatePassSpan.innerHTML = MSG_PASSWORD_FORMAT_ERROR;
		txtLRepatePassSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtLRepatePassSpan.innerHTML = "可以使用";
		txtLRepatePassSpan.style.color = "#4F4F4F";
		return true;		
	}		
}
//密码提问验证
function txtQuestion_check()
{
	var txtQuestion = document.getElementById("txtQues").value;
	var txtQuestionSpan = document.getElementById("tipQues");
		var isValid = regularExpressionValid("txtQues",QUECTION_ANSWER);
	if(txtQuestion=="")
	{
		txtQuestionSpan.innerHTML = MSG_QUESTION_NULL;
		txtQuestionSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtQuestionSpan.innerHTML = MSG_QUESTION_FORMAT_ERROR;
		txtQuestionSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtQuestionSpan.innerHTML = "可以使用";
		txtQuestionSpan.style.color = "#4F4F4F";
		return true;		
	}	
}
//密码回答验证
function txtAnswer_check()
{
	var txtAnswer = document.getElementById("txtAnswer").value;
	var txtAnswerSpan = document.getElementById("tipAnswer");
		var isValid = regularExpressionValid("txtAnswer",QUECTION_ANSWER);
	if(txtAnswer=="")
	{
		txtAnswerSpan.innerHTML = MSG_ANSWER_NULL;
		txtAnswerSpan.style.color = "red";
		return false;
	}
	else if(!isValid)
	{
		txtAnswerSpan.innerHTML = MSG_ANSWER_FORMAT_ERROR;
		txtAnswerSpan.style.color = "red";
		return false;		
	}
	else
	{
		txtAnswerSpan.innerHTML = "可以使用";
		txtAnswerSpan.style.color = "#4F4F4F";
		return true;		
	}	
}
//验证码验证
function txtVer_check()
{
	var txtVer = document.getElementById("txtVer").value;
	var txtVerSpan = document.getElementById("tipVer");
	VercodeValdate.isRightVercode(txtVer,resultCode);
	if(txtVer=="")
	{
		txtVerSpan.innerHTML = MSG_VERIFYCODE_NULL;
		txtVerSpan.style.color = "red";
		return false;
	}
	else
	{
		txtVerSpan.innerHTML = "可以使用";
		txtVerSpan.style.color = "#4F4F4F";
		return true;			
	}
}
function resultCode(data)
{
	if(data==true)
	{
		document.getElementById("validatemsg").disabled=false;	
	}
	else
	{	
		var txtVerSpan = document.getElementById("tipVer");
		txtVerSpan.innerHTML = MSG_VERIFYCODE_ERROR;
		txtVerSpan.style.color = "red";
		document.getElementById("validatemsg").disabled=true;			
	}
}





